package com.boarsoft.gateway.router;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.boarsoft.soagov.route.ServiceRouter;

public class CanaryRouterImpl<T> implements ServiceRouter<HttpServletRequest> {
	private static final Logger log = LoggerFactory.getLogger(CanaryRouterImpl.class);

//	/** 金丝雀开关 */
//	public static volatile boolean canary;
//	/** 可以让不同的测试人员走不同的测试版本 */
//	public static final Set<String> testerSet = ConcurrentHashMap.newKeySet();
//	/** { Key: 服务编号-服务消费者（客户端）版本号， Value：服务提供者（Web应用）版本号 } */
//	public static Properties canaries = new Properties();

	@Override
	public void config() {
//		// 金丝雀开关
//		String s = GatewayConfig.getProperty("canary", "false");
//		log.info("Set canary = {}", s);
//		canary = Boolean.valueOf(s);
//		// 测试人员白名单
//		testerSet.clear();
//		String[] wl = GatewayConfig.getProperty("testers", "").split(",");
//		for (String w : wl) {
//			testerSet.add(w);
//		}
//		// 读取金丝雀版本号
//		ClassLoader cl = GatewayConfig.class.getClassLoader();
//		try {
//			log.info("Load conf/canaries.properties ...");
//			canaries.load(cl.getResourceAsStream("conf/canaries.properties"));
//		} catch (IOException e) {
//			log.error("Error on load conf/canaries.properties.", e);
//		}
	}

	@Override
	public String getProvider(HttpServletRequest req) {
		// TODO 在这里写路由逻辑，返回相应的目标地址
		return "localhost:10101";
	}

}